﻿using BaseUI;
using BLL;
using Model;
using System;
using System.Data;
using System.Web.UI.WebControls;
using Thksoft.Module.DataDetail;

namespace Thksoft.UserCotrols
{
    //public partial class PlanDetailSum_Year : BasePage
    //{
    //    protected void Page_Load(object sender, EventArgs e)
    //    {
    //        BindDt();
    //    }

    //    /// <summary>
    //    /// 导出
    //    /// </summary>
    //    /// <param name="sender"></param>
    //    /// <param name="e"></param>
    //    public void BindDaodu()
    //    {
    //        //toExecl1(Panel1, "年资金计划" + DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Millisecond.ToString());
    //    }

    //    /// <summary>
    //    /// 打印
    //    /// </summary>
    //    /// <param name="sender"></param>
    //    /// <param name="e"></param>
    //    public void BindPrint()
    //    {
    //        //var key = Guid.NewGuid().ToString();
    //        //Session[key] = FORM_PRINT_VALUE.Value;
    //        //MessageBox.ResponseScript(Page, "top.MessageBox.Print({Value:\"ID=HTML&VALUE=" + key + "\",Area:[\"800px\",\"500px\"],Scrollbar:true})");
    //    }

    //    /// <summary>
    //    /// 绑定数据
    //    /// </summary>
    //    public void BindDt()
    //    {
    //        string sql = "";//string.Format(@" select * from qx_planyearapply t where t.N_BUSINESS_STATE NOT IN (0,-1) and t.N_YEAR=" + year + " and t.N_COMPANY_ID=" + cmyId);

    //        DataTable pPage.dtYear = new BaseBLL().Query(sql);
    //        DataTable dt = new DataTable();
    //        //if (pPage.dtYear != null && pPage.dtYear.Rows.Count > 0)
    //        //{
    //        //    var busId = pPage.dtYear.Rows[0]["N_BUSINESS_ID"].ToString();

    //        //    QS_Business bModel = new Qs_BusinessBLL().GetBusinessById(Decimal.Parse(busId));
    //        //    if (bModel != null)
    //        //    {
    //        //        lblTime.Text = bModel.Business_operator_date.ToString("yyyy-MM-dd");

    //        //        lblUser.Text = new Sys_UserBLL().GetInfoById(bModel.Business_operator_Id.ToString()).USER_NAME;
    //        //    }

    //        //    lblyear.Text = pPage.dtYear.Rows[0]["N_YEAR"].ToString();

    //        //    lblBzyj.Text = pPage.dtYear.Rows[0]["C_REAMRK"].ToString();

    //        //    lbldw.Text = new Sys_CompanyBLL().GetInfoById(pPage.dtYear.Rows[0]["N_COMPANY_ID"].ToString()).CMY_NAME;

    //        //    this.hidId.Value = pPage.dtYear.Rows[0]["N_YEARAPP_ID"].ToString() + "@" + busId;

    //        //    dt = new QX_PLANYEARAPPLYBLL().GetDataBind(busId);
    //        //    ViewState["database"] = dt;
    //        //    gvMonthFunds.DataSource = dt;
    //        //    gvMonthFunds.DataBind();
    //        //}
    //        //else
    //        //{
    //        //    //Response.Write("<script>alert('【系统提示】该条数据有误，请与管理员联系');location.href='../Right.aspx';</script>");
    //        //    MessageBox.Show(this, "【系统提示】没有查询到相关数据！");
    //        //    lblTime.Text = "";
    //        //    lblUser.Text = "";
    //        //    lblyear.Text = "";
    //        //    lblBzyj.Text = "";
    //        //    lbldw.Text = "";
    //        //    gvMonthFunds.DataSource = dt;
    //        //    gvMonthFunds.DataBind();
    //        //    return;
    //        //}
    //    }

    //    protected void gvMonthFunds_RowDataBound(object sender, GridViewRowEventArgs e)
    //    {
    //        if (e.Row.RowType == DataControlRowType.DataRow)
    //        {
    //            string type = ((Label)e.Row.FindControl("lbltype")).Text;
    //            if (type == "0")
    //            {
    //                e.Row.Attributes["style"] = "background-color:#B2D8FF;font-size: 14px";
    //            }
    //            else if (type == "1")
    //            {
    //                e.Row.Attributes["style"] = "background-color:#CCCCCC;font-size: 13px;";
    //            }
    //        }
    //    }

    //}

    public partial class PlanDetailSum_Year : BaseControl
    {
        private QX_PLANYEARAPPLYBLL applyWeekBll = new QX_PLANYEARAPPLYBLL();
        public DataTable dt;

        protected void Page_Load(object sender, EventArgs e)
        {
            BindDt();
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        public void BindDt()
        {
            var pPage = this.Page as ProjectFundDetail_Year;
            HiddenField4.Value = pPage.year;
            dt = new DataTable();
            if (pPage.dtYear != null && pPage.dtYear.Rows.Count > 0 && Convert.ToDecimal(pPage.busId) > 0)
            {
                var busId = pPage.dtYear.Rows[0]["N_BUSINESS_ID"].ToString();

                QS_Business bModel = new Qs_BusinessBLL().GetBusinessById(Decimal.Parse(busId));
                if (bModel != null)
                {
                    lblTime.Text = bModel.Business_operator_date.ToString("yyyy-MM-dd");

                    lblUser.Text = new Sys_UserBLL().GetInfoById(bModel.Business_operator_Id.ToString()).USER_NAME;
                }

                lblyear.Text = pPage.dtYear.Rows[0]["N_YEAR"].ToString();

                lblBzyj.Text = pPage.dtYear.Rows[0]["C_REAMRK"].ToString();

                lbldw.Text = new Sys_CompanyBLL().GetInfoById(pPage.dtYear.Rows[0]["N_COMPANY_ID"].ToString()).CMY_NAME;

                this.hidId.Value = pPage.dtYear.Rows[0]["N_YEARAPP_ID"].ToString() + "@" + busId;

                dt = new QX_PLANYEARAPPLYBLL().GetDataBind(busId);
                ViewState["database"] = dt;
                gvMonthFunds.DataSource = dt;
                gvMonthFunds.DataBind();
            }
            else
            {
                //Response.Write("<script>alert('【系统提示】该条数据有误，请与管理员联系');location.href='../Right.aspx';</script>");
                MessageBox.Show(Page, "【系统提示】没有查询到相关数据！");
                lblTime.Text = "";
                lblUser.Text = "";
                lblyear.Text = "";
                lblBzyj.Text = "";
                lbldw.Text = "";
                gvMonthFunds.DataSource = dt;
                gvMonthFunds.DataBind();
                return;
            }
        }

        protected void gvMonthFunds_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string type = ((Label)e.Row.FindControl("lbltype")).Text;
                //var ifdetails = ((HiddenField)e.Row.FindControl("HiddenField1")).Value == "1" ? true : false;
                string sss = ((Label)e.Row.FindControl("lblProID")).Text;
                if (type == "0")
                {
                    e.Row.Attributes["style"] = "background-color:#B2D8FF;font-size: 14px";
                }
                else if (type == "1")
                {
                    e.Row.Attributes["style"] = "background-color:#CCCCCC;font-size: 13px;";
                }
            }
        }

        public void BindDaodu()
        {
            var execll = new BasePage();
            execll.toExecl1(Panel1, "年资金计划申请表" + DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Millisecond.ToString());
        }

        public void BindPrint()
        {
            var key = Guid.NewGuid().ToString();
            MessageBox.ResponseScript(Page, "top.MessageBox.Print({Value:\"ID=HTML&VALUE=" + key + "\",Area:[\"800px\",\"500px\"],Scrollbar:true})");
        }
    }
}